<?php
class Admin_Form_Menu extends Zend_Form{
	protected $_title;
	protected $_type; // Create or Update
	protected $_submit;
	protected $_menuname;
	protected $_description;
	protected $_imagefile;

	public function __construct($type) {
		parent::__construct();
		$this->_type = $type;
		$this->create($this->_type);
	}

	// Create form base on type.
	protected function create($type) {
		$titleStr  = '';
		$submitStr = '';
		$url = new Zend_View_Helper_Url();
		$action = ' ';
		if ($type == 'create') {
			$action = $url->url(array('module'=>'admin', 'controller'=> 'menu','action'=>'addmenu'),'default');
			$submitStr = 'Create';
			$titleStr = 'Add menu';
		} else if ($type == 'update'){
			$action = $url->url(array('module'=>'admin', 'controller'=> 'menu','action'=>'updatemenu'),'default');
			$submitStr = 'Update';
			$titleStr = 'Update menu';
		}
		$this->setName($submitStr);
		$this->setAttrib('enctype', 'multipart/form-data');
		$this->setAction($action);

		//table

		$this->_title = new Zend_Form_Decorator_Captcha();
		$this->_title->render($titleStr);

		$this->_menuname = new Zend_Form_Element_Text('menuname');
		$this->_menuname->setLabel('Menu name: ')
		->setRequired(true)
		->addValidator('NotEmpty');

		$this->_description = new Zend_Form_Element_Textarea('description');
		$this->_description->setLabel('Description: ')
		->setAttrib('rows', '5');


		$this->_imagefile = new Zend_Form_Element_File('menuimage_path');
		$this->_imagefile->setLabel('Document File Path');
		$this->_imagefile->setName('menuimage')
		//->setRequired(true)
		->addValidator('Extension', false, 'jpg,png,gif');

		$this->_submit = new Zend_Form_Element_Submit('submit');
		$this->_submit->setLabel($submitStr);

		$this->addElements(array($this->_title, $this->_menuname, $this->_description, $this->_imagefile, $this->_submit));
	}

	public function populateData(Front_Model_Menu $menuInfo) {
		if (isset($menuInfo->_description)) {
			$this->_description->setValue($menuInfo->_description);
		}

		if (isset($menuInfo->_menuimage)) {
			//$this->_description->setValue($menuInfo->_description);
		}

		if (isset($menuInfo->_menuname)) {
			$this->_menuname->setValue($menuInfo->_menuname);
		}
	}

}